<?php

namespace App\Http\Controllers\Web\Member\Seller;

use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;

class UserCommentController extends BaseController
{
    protected $api_url = [
        'show' => ['get', 'seller/orders/%d/user_comment/%d'],
        'store' => ['post', 'seller/orders/%d/user_comment'],
        'show_order' => ['get', 'seller/orders/%d'],
    ];

    protected $api_host;

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->api_host = config('url.api_web');
    }

    public function show($order_id, $comment_id)
    {
        //请求部分
        $user_comment_ret = http_web($this->api_url['show'], [$order_id, $comment_id])->auto(false)->send();

        //请求部分-买家评价
        $order = http_web($this->api_url['show_order'], [$order_id])->send(['with' => 'orderProductComment']);

//        dd($order);
        return view('web.user.seller.common.comment', ['order_id' => $order_id, 'user_comment' => $user_comment_ret['data'],'order_product_comment'=>$order['data']['order_product_comment']]);
    }

    public function store($order_id)
    {
        $this->validate($this->request, [
            'overall' => 'required|in:1,2,3',
            'comment' => 'required',
        ]);
        $data = $this->request->all(['overall', 'comment']);

        $ret = http_web($this->api_url['store'], [$order_id])->send($data);
        return $ret;
    }
}